package org.ellisande.grid.tags;

import javax.servlet.jsp.JspWriter;

import org.ellisande.grid.tags.support.TagBuilder;
import org.ellisande.tld.annotations.Attribute;
import org.ellisande.tld.annotations.Description;

public class TextareaTag extends InputTag {

	private static final long serialVersionUID = -4112594068053891280L;
	
	@Attribute
	@Description("Defines the number of rows this textarea should contain. Allowed values: 1-INT_MAX. Default is 3.")
	private int rows = 3;
	
	private TagBuilder textarea = createTagBuilder("textarea");
	private TagBuilder div = createTagBuilder("div");
	
	private static final String DIV_STYLE = "controls";

	@Override
	public void startTag() throws Exception {
		div.addStyle(DIV_STYLE);
		textarea.addAttribute("rows",Integer.toString(rows));
		JspWriter out = pageContext.getOut();
		out.write(div.compileStartTag());
		out.write(textarea.compileStartTag());
	}

	@Override
	public void endTag() throws Exception {
		JspWriter out = pageContext.getOut();
		out.write(textarea.compileEndTag());
		out.write(div.compileEndTag());
	}
	
	@Override
	public void release(){
		super.release();
		textarea = null;
		div = null;
		rows = 3;
	}

}
